// (c) Copyright 2013 Mike Riedel.
// This source is subject to the Microsoft Public License (Ms-PL).
// All other rights reserved.

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FreshMeat.MiniHsmTest
{
   [TestClass]
   public class PelicanTest
   {
      [TestMethod]
      public void OnOffTest()
      {
         var pelican = new Pelican();
         Assert.AreEqual(true, pelican.Power);
         Assert.AreEqual(Pelican.Vehicle.Green, pelican.Cars);
         Assert.AreEqual(Pelican.Ped.DontWalk, pelican.Peds);

         pelican.Update(Pelican.Input.PowerOff);

         Assert.AreEqual(false, pelican.Power);
      }

      [TestMethod]
      public void FullTest()
      {
         var pelican = new Pelican();
         for (var i = 0; i < 5; i++)
            Exercise(pelican, i);
      }

      static void Exercise(Pelican pelican, int count)
      {
         Assert.AreEqual(Pelican.Vehicle.Green, pelican.Cars, "count = {0}", count);
         Assert.AreEqual(Pelican.Ped.DontWalk, pelican.Peds, "count = {0}", count);
         Assert.AreEqual(30, pelican.Timer);

         pelican.Update(Pelican.Input.PedWaiting);
         pelican.Update(Pelican.Input.TimerExpired);

         Assert.AreEqual(Pelican.Vehicle.Yellow, pelican.Cars, "count = {0}", count);
         Assert.AreEqual(Pelican.Ped.DontWalk, pelican.Peds, "count = {0}", count);

         pelican.Update(Pelican.Input.TimerExpired);

         Assert.AreEqual(Pelican.Vehicle.Red, pelican.Cars, "count = {0}", count);
         Assert.AreEqual(Pelican.Ped.Walk, pelican.Peds, "count = {0}", count);

         pelican.Update(Pelican.Input.TimerExpired);

         Assert.AreEqual(Pelican.Vehicle.Red, pelican.Cars, "count = {0}", count);
         Assert.AreEqual(Pelican.Ped.Flash, pelican.Peds, "count = {0}", count);

         pelican.Update(Pelican.Input.TimerExpired);

         Assert.AreEqual(Pelican.Vehicle.Green, pelican.Cars, "count = {0}", count);
         Assert.AreEqual(Pelican.Ped.DontWalk, pelican.Peds, "count = {0}", count);
      }

      [TestMethod]
      public void PelicanPerfTest()
      {
         var pelican = new Pelican();
         for (var i = 0; i < 500000; i++)
            PerfTest(pelican);
      }

      static void PerfTest(Pelican pelican)
      {
         pelican.Update(Pelican.Input.PedWaiting);
         pelican.Update(Pelican.Input.TimerExpired);
         pelican.Update(Pelican.Input.TimerExpired);
         pelican.Update(Pelican.Input.TimerExpired);
         pelican.Update(Pelican.Input.TimerExpired);
      }
   }
}